home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: NEwbie: How to return a multi-dimensional array from function?
- Date: 9 Mar 1996 18:18:39 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4ht3kf$vg@umbc9.umbc.edu>
- References: <4hp273$8bu@news.xs4all.nl> <31404CE9.1A4A@mc.net>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Anthony Moendir wrote:
- >> I want to return a multidimensional array fro a function,
-
- Sean Park <spark@mc.net> wrote:
- > You could pass the pointer to the array to the function. That way the
- > function itself will fill your array addresses rather than returning
- > redundant data. You might try:
- >
- > void foo(char *tmp);
- > int main()
- > {
- > char tmp[10][5];
- > foo(tmp);
- > return 0;
- > }
- > void foo(char *tmp)
- > {
- > /* You can reference tmp within this function as an array of what ever
- > * dimensions you want. */
- > /* do something */
- >
- > return;
- > }
-
- How is passing a 2D array of char, pretending to be a pointer to char,
- to a function and making changes what the original poster asked for?
- I would prototype 'foo' as either:
-
- void foo (char *tmp[5]);
- void foo (char tmp[][5]);
- void foo (char tmp[10][5]);
-
- And then use it as a 2D array as would be expected from the way it was
- declared in main().
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-